﻿using HY.Common;
using HY.Entity;
using HY.Service;
using HY.Web.Controllers;
using HY.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HY.Web.Areas.Local.Controllers
{
    public class RegionController : BaseController
    {
        BaseService baseService = new BaseService();

        [AllowAnonymous]
        [HttpPost]
        public JsonResult List(int? code)
        {
            ReturnModel returnModel = new ReturnModel();
            try
            {
                var list = baseService.EFGetMany<Region>(e => e.ParentCode == code).Select(s => new { value = s.RegionCode, text = s.RegionName });
                returnModel = GetReturnModel(list.Count(), list);
            }
            catch (Exception ex)
            {
                returnModel = base.GetReturnModel(ex);
                LogHelper.Error("获取地区失败", ex);
            }
            return Json(returnModel);
        }
    }
}